﻿using System.Collections;
using System.Collections.Generic;

namespace Cfg
{
    public class ConfigKeyValues : IEnumerable<KeyValuePair<string, string>>
    {
        private readonly Dictionary<string, string> _dict = new Dictionary<string, string>();

        public string this[string key]
        {
            get
            {
                key = key.ToLower();
                if (_dict.ContainsKey(key))
                    return _dict[key];

                return null;
            }
            set
            {
                _dict[key.ToLower()] = value;
            }
        }

        public int Count { get { return _dict.Count; } }

        public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
        {
            return _dict.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public ConfigKeyValues Add(string key, string value)
        {
            this[key] = value;
            return this;
        }
    }
}
